#include <iostream>
using namespace std;

// 起泡排序函数
void bubbleSort(int arr[], int n) {
    for (int i = 0; i < n - 1; ++i) {
        for (int j = 0; j < n - i - 1; ++j) {
            if (arr[j] > arr[j + 1]) {
                // 交换 arr[j] 和 arr[j + 1]
                int temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j + 1] = temp;
            }
        }
    }
}

int main() {
    int n ;
    cout << "请输入数组的长度: ";
    cin >> n;
    int R[n];

    cout << "请输入 " << n << " 个整数: ";
    for (int i = 0; i < n; i++) {
        cin >> R[i];
    }

    cout << "排序前的数组: ";
    for (int i = 0; i < n; i++) {
        cout << R[i] << " ";
    }
    cout << endl;

    bubbleSort(R, n);

    cout << "排序后的数组: ";
    for (int i = 0; i < n; i++) {
        cout << R[i] << " ";
    }
    cout << endl;

    return 0;
}